package com.sunedai.tiger.web.controller.emp.system;

import com.sunedai.tiger.common.enumeration.EnumDictType;
import com.sunedai.tiger.dao.system.entity.Dictionary;
import com.sunedai.tiger.service.system.DictionaryService;
import com.sunedai.tiger.web.controller.emp.BaseEmpController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 数据字典控制器
 *
 * @author zhaolipeng
 */
@Controller
@RequestMapping("/emp/sys/dict")
public class EmpDictionaryController extends BaseEmpController {

  @Resource
  private DictionaryService dictionaryService;

  @GetMapping
  public ModelAndView dict() {
    ModelAndView view = new ModelAndView("sys.dict");
    view.addObject("totalRecords", dictionaryService.count());
    return view;
  }

  @GetMapping("/list")
  @ResponseBody
  public List<Dictionary> list(@RequestParam int p, @RequestParam int max) {
    return dictionaryService.list(p, max);
  }

  @PostMapping("/save_update")
  @ResponseBody
  public Dictionary saveOrUpdate(@ModelAttribute Dictionary dictionary) {
    return dictionaryService.saveOrUpdate(dictionary, getLoginUsrId());
  }

  @PostMapping("/find_type")
  @ResponseBody
  public Map<String, String> findType() {
    return EnumDictType.getEnumDictTypes();
  }




}
